package com.apes.fn.tms.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.soe.annotations.State;
import com.apes.framework.plugin.soe.annotations.States;
import com.apes.scm.masterdata.stock.model.PhyDepot;
import lombok.Getter;
import lombok.Setter;
import org.apache.ibatis.annotations.One;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * 运单线路规划
 * @author yiny
 * Date 2020.3.23
 */
@Setter
@Getter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = WaybillPlanningPlan.CONST_TABLE_NAME)
public class WaybillPlanningPlan extends BaseModel {
    public static final String CONST_TABLE_NAME = "TMS_waybill_planning_plan";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "运单线路规划")
    @Comment("编码")
    private String id;

    @Column(name = "plan_number")
    @Comment("方案号")
    private int planNumber;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "waybill_id", referencedColumnName = "id")
    @Comment("运单号")
    private Waybill waybillId;

    @Column(name = "execution_number")
    @Comment("执行序号")
    private int executionNumber;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "line_id", referencedColumnName = "id")
    @Comment("线路ID")
    private BranchLine lineId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "delivery_address", referencedColumnName = "id")
    @Comment("发货地址")
    private PhyDepot deliveryAddress;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "shipping_address", referencedColumnName = "id")
    @Comment("收货地址")
    private PhyDepot shippingAddress;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "car_infomation_id", referencedColumnName = "id")
    @Comment("派车单号")
    private CarInformation carInformationId;

    @Column(name = "loading_time")
    @Comment("装车时间")
    private Date loadingTime;

    @Column(name = "arrival_time")
    @Comment("到达时间")
    private Date arrivalTime;

    @States(name = "状态",
            values = {@State(id="sendCar", name="待派车"), @State(id="loading", name = "待装车"), @State(id="inTransit", name="运输中"),
                    @State(id="arrived", name="已送达")})
    @Column(name = "status")
    @Comment("状态")
    private String status;

}
